package totask.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import totask.pojo.TotaskProject;
import totask.pojo.TotaskTaskstatus;
import totask.response.ResponseData;
import totask.service.impl.ProjectServiceImpl;
import totask.service.impl.StatusServiceImpl;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import java.util.List;

@Api(tags = "项目信息")
@RestController
@Validated
@RequestMapping("/project")
public class ProjectController {
    @Autowired
    private ProjectServiceImpl projectService;

    @Resource
    private StatusServiceImpl statusService;


    @ApiOperation("根据任务id查询任务状态信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "TaskStatusId", value = "任务id", dataType = "Integer", required = true),
    })
    @GetMapping("/queryByStatus")
    public ResponseData<TotaskTaskstatus> queryByStatus(@RequestParam  @Min(value = 1, message = "任务id不能小于1")  Integer TaskStatusId){
        return new ResponseData<TotaskTaskstatus>().success(statusService.queryByStatus(TaskStatusId));
    }

    @ApiOperation("根据项目创建人查询项目信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "CreateNameId", value = "项目创建人（项目经理）", dataType = "String", required = true),
    })
    @PostMapping("/ProjectInfo")
    public ResponseData<List<TotaskProject>> queryProject(@RequestParam  @NotBlank(message = "项目创建人不能为空") String CreateNameId){
        return new ResponseData<List<TotaskProject>>().success(projectService.queryProject(CreateNameId));
    }

    @ApiOperation("新建项目信息")
    @PostMapping("/insertProjectInfo")
    public ResponseData insertProject(@Valid  @RequestBody TotaskProject totaskProject){
        ResponseData responseData = new ResponseData();
        responseData.setData(projectService.insertProject(totaskProject));
        return responseData.success();
    }
    @ApiOperation("根据项目id删除项目所有信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectId", value = "项目id", dataType = "Integer", required = true),
    })
    @GetMapping("/deleteProjectInfo")
    public ResponseData deleteProject(@RequestParam  @Min(value = 1, message = "项目id不能小于1") Integer projectId){
        ResponseData responseData = new ResponseData();
        responseData.setData(projectService.deleteProject(projectId));
        return responseData.success();
    }

    @ApiOperation("根据项目id修改创建人")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectId", value = "项目id", dataType = "Integer", required = true),
            @ApiImplicitParam(name = "createnameid", value = "项目创建人（项目经理）", dataType = "String", required = true)
    })
    @PostMapping("/updateProjectInfo")
    public ResponseData updateProject(@RequestParam  @Min(value = 1, message = "项目id不能小于1") Integer projectId,
                                      @RequestParam  @NotBlank(message = "项目创建人不能为空")String createnameid){
        ResponseData responseData = new ResponseData();
        responseData.setData(projectService.updateProject(projectId,createnameid));
        return responseData.success();
    }

    @ApiOperation("根据项目id查询用户项目")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectId", value = "项目id", dataType = "Integer", required = true),
    })
    @GetMapping("/queryUserProjectinfo")
    public ResponseData queryUserProjectAll(@RequestParam  @Min(value = 1, message ="项目id不能小于1")Integer projectId){
        return new ResponseData().success(projectService.queryUserProjectAll(projectId));
    }
}
